<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Gets a DOMElement object from a
   SimpleXMLElement object</title>
 </head>
 <body class="docs"></div>
<div id="layout">
  <div id="layout-content"><div id="function.dom-import-simplexml" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">dom_import_simplexml</h1>
  <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">dom_import_simplexml</span> &mdash; <span class="dc-title">
   Gets a <a href="class.domelement.html" class="classname">DOMElement</a> object from a
   <a href="class.simplexmlelement.html" class="classname">SimpleXMLElement</a> object
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.dom-import-simplexml-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>dom_import_simplexml</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span> <code class="parameter">$node</code></span>
   ) : <span class="type"><a href="class.domelement.html" class="type DOMElement">DOMElement</a></span></div>

  <p class="para rdfs-comment">
   This function takes the node <code class="parameter">node</code> of class
   <a href="ref.simplexml.html" class="link">SimpleXML</a> and makes it into a
   <a href="class.domelement.html" class="classname">DOMElement</a> node. This new object can then be used
   as a native <a href="class.domelement.html" class="classname">DOMElement</a> node. 
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.dom-import-simplexml-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">node</code></dt>

     <dd>

      <p class="para">
       The <a href="class.simplexmlelement.html" class="classname">SimpleXMLElement</a> node.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.dom-import-simplexml-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The <a href="class.domelement.html" class="classname">DOMElement</a> node added or <strong><code>FALSE</code></strong> if any errors occur.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.dom-import-simplexml-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-6510">
   <p><strong>Example #1 Import SimpleXML into DOM with <span class="function"><strong>dom_import_simplexml()</strong></span></strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$sxe&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">simplexml_load_string</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;books&gt;&lt;book&gt;&lt;title&gt;blah&lt;/title&gt;&lt;/book&gt;&lt;/books&gt;'</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$sxe&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Error&nbsp;while&nbsp;parsing&nbsp;the&nbsp;document'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$dom_sxe&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dom_import_simplexml</span><span style="color: #007700">(</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$dom_sxe</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Error&nbsp;while&nbsp;converting&nbsp;XML'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$dom&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">(</span><span style="color: #DD0000">'1.0'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dom_sxe&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">importNode</span><span style="color: #007700">(</span><span style="color: #0000BB">$dom_sxe</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dom_sxe&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">appendChild</span><span style="color: #007700">(</span><span style="color: #0000BB">$dom_sxe</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.dom-import-simplexml-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="simplexml_import_dom.html" class="function" rel="rdfs-seeAlso">simplexml_import_dom()</a> - Get a SimpleXMLElement object from a DOM node</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>